<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>FileCopyDir</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>FileCopyDir</h1>

<p>Copies a folder along with all its sub-folders and files (similar to xcopy).</p>

<pre class="Syntax">FileCopyDir, Source, Dest [, Flag]</pre>
<h3>Parameters</h3>
<dl>

  <dt>Source</dt>
  <dd><p>Name of the source directory (with no trailing backslash), which is assumed to be in <a href="../Variables.htm#WorkingDir">%A_WorkingDir%</a> if an absolute path isn't specified. For example: C:\My Folder</p></dd>

  <dt>Dest</dt>
  <dd><p>Name of the destination directory (with no trailing baskslash), which is assumed to be in <a href="../Variables.htm#WorkingDir">%A_WorkingDir%</a> if an absolute path isn't specified. For example: C:\Copy of My Folder</p></dd>

  <dt>Flag</dt>
  <dd><p>(optional) this flag determines whether to overwrite files 
        if they already exist:</p>
      <p><strong>0</strong> (default): Do not overwrite existing files. The operation will fail and have no effect if <em>Dest</em> already exists as a file or directory.</p>
      <p><strong>1</strong>: Overwrite existing files. However, any files or subfolders inside <em>Dest</em> that do not have a counterpart in <em>Source</em> will not be deleted.</p>
      <p>This parameter can be an <a href="../Variables.htm#Expressions">expression</a>, even one that evalutes to true or false (since true and false are stored internally as 1 and 0).</p></dd>

</dl>

<h3>ErrorLevel</h3>
<p><span class="ver">[v1.1.04+]</span> This command is able to throw an exception on failure. For more information, see <a href="Catch.htm#RuntimeErrors">Runtime Errors</a>.</p>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if there was a problem or 0 otherwise. However, if the source directory contains any saved webpages consisting of a <em>PageName.htm</em> file and a corresponding directory named <em>PageName_files</em>, an error may be indicated even when the copy is successful.</p>
<h3>Remarks</h3>
<p>If the destination directory structure doesn't exist it will be created if possible.</p>
<p>Since the operation will recursively copy a folder along with all its subfolders and files, the result of copying a folder to a destination somewhere inside itself is undefined. To work around this, first copy it to a destination outside itself, then use <a href="FileMoveDir.htm">FileMoveDir</a> to move that copy to the desired location.</p>
<p>FileCopyDir copies a single folder. To instead copy the contents of a folder (all its files and subfolders), see the examples section of <a href="FileCopy.htm">FileCopy</a>.</p>
<h3>Related</h3>
<p><a href="FileMoveDir.htm">FileMoveDir</a>, <a href="FileCopy.htm">FileCopy</a>, <a href="FileMove.htm">FileMove</a>, <a href="FileDelete.htm">FileDelete</a>, <a href="LoopFile.htm">file-loops</a>, <a href="FileSelectFolder.htm">FileSelectFolder</a>, <a href="SplitPath.htm">SplitPath</a></p>
<h3>Examples</h3>
<pre class="NoIndent">FileCopyDir, C:\My Folder, C:\Copy of My Folder

<em>; Example #2: A working script that prompts you to copy a folder.</em>
FileSelectFolder, SourceFolder, , 3, Select the folder to copy
if SourceFolder =
    return
<em>; Otherwise, continue.</em>
FileSelectFolder, TargetFolder, , 3, Select the folder IN WHICH to create the duplicate folder.
if TargetFolder =
    return
<em>; Otherwise, continue.</em>
MsgBox, 4, , A copy of the folder &quot;%SourceFolder%&quot; will be put into &quot;%TargetFolder%&quot;.  Continue?
IfMsgBox, No
    return
SplitPath, SourceFolder, SourceFolderName  <em>; Extract only the folder name from its full path.</em>
FileCopyDir, %SourceFolder%, %TargetFolder%\%SourceFolderName%
if ErrorLevel
    MsgBox The folder could not be copied, perhaps because a folder of that name already exists in &quot;%TargetFolder%&quot;.
return</pre>

</body>
</html>
